#include "Components/ComponentSpawn.h"
#include "Subsystems/SubsystemGameInfo.h"
#include "Subsystems/SubsystemAnimalEntities.h"
#include "GameSingleton.h"

#include "Log.h"

namespace PocketSurvival
{

    void ComponentSpawn::despawn()
    {
        if(isToRemove != true)
        {
            isToRemove = true;
            SubsystemAnimalEntities *subsystemAnimalEntities = GameSingleton::singletonPtr->getSingleton<SubsystemAnimalEntities>();
            subsystemAnimalEntities->removeAnimalEntity(entity);

            // Log::Info("移除掉Animal");
        }
    }

    static const std::string componentName = "Spawn";
    const std::string &ComponentSpawn::getName() const
    {
        return componentName;
    }
    const std::string &ComponentSpawn::GetName()
    {
        return componentName;
    }
    void ComponentSpawn::load(const nlohmann::json &jsonData)
    {
        isToRemove = false;
        spawnTime = jsonData["SpawnTime"].get<double>();
    }
    void ComponentSpawn::save(nlohmann::json &jsonData)
    {
    }
    void ComponentSpawn::saveToMsgJson(nlohmann::json &jsonData)
    {
        MSG_VALUE_SET(jsonData, "SpawnTime", "double", spawnTime);
    }
} // namespace PocketSurvival
